package com.qcq.wecheck.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.qcq.wecheck.entity.UserSchedule;
import com.qcq.wecheck.mapper.UserScheduleMapper;
import com.qcq.wecheck.service.AttendanceService;
import com.qcq.wecheck.service.UserScheduleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户-考勤表 中间表 服务实现类
 * </p>
 *
 * @author O
 * @since 2018-09-24
 */
@Service
public class UserScheduleServiceImpl extends ServiceImpl<UserScheduleMapper, UserSchedule> implements UserScheduleService {
	@Resource
	private UserScheduleMapper userScheduleMapper;
	@Resource
	private AttendanceService attendanceService;

	@Override
	public boolean quitAndDeleteHistory(Long scheduleId, String openId) {
		attendanceService.deleteHistory(scheduleId, openId);
		return userScheduleMapper.quit(scheduleId, openId);
	}

	@Override
	public boolean isEngaged(String openId, Long scheduleId) {
		UserSchedule userSchedule = new UserSchedule();
		userSchedule.setOpenId(openId)
				.setScheduleId(scheduleId);
		return userScheduleMapper.selectOne(userSchedule) != null;
	}
}
